// person.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    studentInfo: {},
    defaultAvatarUrl: defaultAvatarUrl,
    show: false,
  },

  onLoad() {
    this.loadStudentInfo();
  },

  toDetail(){
    wx.navigateTo({
      url: '/pages/personDetail/personDetail',
    })
  },

  onShow() {
    this.loadStudentInfo();
  },

  // 从本地存储加载学生信息
  loadStudentInfo() {
    const studentInfo = wx.getStorageSync('studentInfo');
    if (studentInfo) {
      this.setData({
        studentInfo: studentInfo
      });
    } else {
      // 如果没有登录信息，跳转到登录页
      wx.redirectTo({
        url: '/pages/logs/logs'
      });
    }
  },

  showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },

  // 客服相关功能
  contactCustomerService() {
    wx.showToast({
      title: '即将打开在线客服',
      icon: 'none'
    });
  },

  makePhoneCall() {
    wx.makePhoneCall({
      phoneNumber: '400-123-4567'
    });
  },

  sendEmail() {
    wx.setClipboardData({
      data: 'service@example.com',
      success: () => {
        wx.showToast({
          title: '邮箱已复制',
          icon: 'success'
        });
      }
    });
  }
})